package com.fun.xml2Json.javaXbean.javaBean2xml;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import java.io.StringWriter;
import java.util.HashMap;
import java.util.Map;

/**
 * @author liyiruo
 * @Description
 * @Date 2021/6/23 下午1:57
 */
public class b2xmlTest {

    public  static void main(String[ ] args) throws JAXBException {

        A country = new A();
        B b=new B();
        C c=new C();
       Map map=new HashMap<>();
        b.setId(1);
        b.setName("B");
        c.setId(3);
        c.setName("C");
        country.setB(b);
        country.setC(c);
        country.setEntity(map);

        JAXBContext context = JAXBContext.newInstance(A.class);
        Marshaller marshaller = context.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT,true);
        StringWriter writer = new StringWriter();
        marshaller.marshal(country, writer);
        System.out.println(writer.toString());
    }
}
